617C - Watering Flowers - CodeForces Solution


implementation *1600

Please click on ads to support us..

C++ Code:

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
long long c[200010][5];
map<long long,long long>m1,m2;
map< pair<long,long>,long long>m3;
struct p{
	long long r1,r2;
}a[2020];
bool cmp1(p x,p y)
{
	if(x.r1==y.r1)return x.r2<y.r2;
	else return x.r1<y.r1;
}
bool cmp2(p x,p y)
{
	if(x.r2==y.r2)return x.r1<y.r1;
	else return x.r2<y.r2;
}
int main()
{
	long long n,x1,x2,y1,y2,x,y;
	long long rr1=0,rr2=0,sum1=0,sum2=0;
	cin>>n>>x1>>y1>>x2>>y2;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		a[i].r1=(x-x1)*(x-x1)+(y-y1)*(y-y1);
		a[i].r2=(x-x2)*(x-x2)+(y-y2)*(y-y2);
		if(i==1)
		{
			sum1=a[i].r1;
		}
		if(a[i].r1>sum1)sum1=a[i].r1;
	}
	sort(a+1,a+n+1,cmp1);
	long long sum=sum1;
	a[0].r1=0;
	for(int i=n;i>0;i--)
	{
		sum1=a[i-1].r1;
		if(a[i].r2>sum2)sum2=a[i].r2;
		if(sum1+sum2<sum)sum=sum1+sum2;
	}
	cout<<sum<<endl;
}
	 	 			  	  			    	  	 	 				


Comments

Submit
0 Comments
More Questions

1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel